﻿// 数据库管理类开发.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "sqlite3.h"
#pragma comment(lib,"sqlite3.lib")
#include <iostream>
using namespace std;

int main()
{
	sqlite3* DB=NULL;	//声明sqlite3对象
	int stat = sqlite3_open("../test1.db", &DB);	//打开sqlite3文件（或自动创建）
	if (stat != SQLITE_OK)
	{
		cout << "打开文件失败" << endl;
		return 0;
	}
	cout << "文件打开成功" << endl;
	//创建表结构
	string sql;
	sql = "CREATE TABLE Target (ID  INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,Comment  TEXT);";
	sqlite3_exec(DB, sql.c_str(),NULL, NULL, NULL);
	sql = "CREATE TABLE Tag (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,Name  TEXT,Comment TEXT, Refer TEXT);";
	sqlite3_exec(DB, sql.c_str(), NULL, NULL, NULL);
	sql = "CREATE TABLE Map_Target_Tag (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,TargetID  INTEGER,TagID INTEGER); ";
	sqlite3_exec(DB, sql.c_str(), NULL, NULL, NULL);
	sql = "CREATE TABLE Map_Tag_Tag (ID  INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL ,ParentID INTEGER,ChildID INTEGER); ";
	sqlite3_exec(DB, sql.c_str(), NULL, NULL, NULL);

	sqlite3_close(DB);
	return 0;
}
